package com.oracle.application.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.oracle.application.entity.Member;
import com.oracle.application.entity.vo.MemberVo;
import com.oracle.application.service.IMemberService;
import com.oracle.application.vo.R;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author The Bug Maker
 * @since 2021-07-08
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private IMemberService iMemberServicel;

    @GetMapping("/verifyEmail")
    public R verifyEmail(@RequestParam(name = "email") String email){
        int i = iMemberServicel.verifyEmail(email,true);
        R resultR=new R();
        if (i == 0){
            resultR.setCode(200);
            resultR.setMsg("ok");
        }else{
            resultR.setCode(201);
            resultR.setMsg("邮箱已被使用！");
        }
        return resultR;

    }

    @PostMapping("/registerMember")
    public R register(@RequestBody MemberVo memberVo){
        return iMemberServicel.registerMember(memberVo);
    }

    @GetMapping("/getMemberByLoginname")
    public R<MemberVo> loginMember(@RequestParam("loginname") String loginname){
        Member m = new Member();
        m.setLoginname(loginname);
        QueryWrapper<Member> wrapper=new QueryWrapper<>(m);
//        wrapper.eq("loginname", loginname);
        Member one = iMemberServicel.getOne(wrapper);
        MemberVo memberVo = new MemberVo();
        BeanUtils.copyProperties(one, memberVo);
        return new R<>(200, "ok", memberVo);
    }
}
